package com.jf.apply_car.util;

import lombok.Data;

import java.util.List;

@Data
public class ResultJson {

    private static final Integer SUCCESS_CODE = 200;
    private static final Integer ERROR_CODE = 500;
    private static final String SUCCESS_MSG = "success";
    private static final String ERROR_MSG = "服务器异常，请稍后再试";


    private Integer code;
    private String msg;
    private Long count;
    private Object data;

    public static ResultJson page(long count, List<?> list) {
        ResultJson resultJson = new ResultJson();
        resultJson.setCode(0);
        resultJson.setMsg("暂无数据");
        resultJson.setCount(count);
        resultJson.setData(list);
        return resultJson;
    }


    public static ResultJson success(String msg) {
        ResultJson resultJson = new ResultJson();
        resultJson.setCode(SUCCESS_CODE);
        resultJson.setMsg(msg);
        return resultJson;
    }

    public static ResultJson success() {
        return success(SUCCESS_MSG);
    }

    public static ResultJson success(Object data) {
        ResultJson resultJson = new ResultJson();
        resultJson.setCode(SUCCESS_CODE);
        resultJson.setMsg(SUCCESS_MSG);
        resultJson.setData(data);
        return resultJson;
    }

    public static ResultJson error(Integer code, String msg) {
        ResultJson resultJson = new ResultJson();
        resultJson.setCode(code);
        resultJson.setMsg(msg);
        return resultJson;
    }

    public static ResultJson error(Integer code) {
        return error(code, ERROR_MSG);
    }

    public static ResultJson error(String msg) {
        return error(ERROR_CODE, msg);
    }

}
